home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 726-750 / 741 / rkrm_lib1 / rkrm_lib1.lha / Intuition / Windows / winpubscreen.c < prev   
C/C++ Source or Header  |  1992-09-03  |  4KB  |  131 lines

  1. ;/* winpubscreen.c - Execute me to compile me with SAS C 5.10
  2. LC -b1 -cfistq -v -y -j73 winpubscreen.c
  3. Blink FROM LIB:c.o,winpubscreen.o TO winpubscreen LIBRARY LIB:LC.lib,LIB:Amiga.lib
  4. quit
  5. */
  6.  
  7. /*
  8. Copyright (c) 1992 Commodore-Amiga, Inc.
  9.  
  10. This example is provided in electronic form by Commodore-Amiga, Inc. for
  11. use with the "Amiga ROM Kernel Reference Manual: Libraries", 3rd Edition,
  12. published by Addison-Wesley (ISBN 0-201-56774-1).
  13.  
  14. The "Amiga ROM Kernel Reference Manual: Libraries" contains additional
  15. information on the correct usage of the techniques and operating system
  16. functions presented in these examples.  The source and executable code
  17. of these examples may only be distributed in free electronic form, via
  18. bulletin board or as part of a fully non-commercial and freely
  19. redistributable diskette.  Both the source and executable code (including
  20. comments) must be included, without modification, in any copy.  This
  21. example may not be published in printed form or distributed with any
  22. commercial product.  However, the programming techniques and support
  23. routines set forth in these examples may be used in the development
  24. of original executable software products for Commodore Amiga computers.
  25.  
  26. All other rights reserved.
  27.  
  28. This example is provided "as-is" and is subject to change; no
  29. warranties are made.  All use is at your own risk. No liability or
  30. responsibility is assumed.
  31. */
  32.  
  33.  
  34. /*
  35. ** winpubscreen.c
  36. ** open a window on the default public screen (usually the Workbench screen)
  37. */
  38.  
  39. #define INTUI_V36_NAMES_ONLY
  40.  
  41. #include <exec/types.h>
  42. #include <intuition/intuition.h>
  43.  
  44. #include <clib/exec_protos.h>
  45. #include <clib/intuition_protos.h>
  46.  
  47. #ifdef LATTICE
  48. int CXBRK(void)    { return(0); }  /* Disable Lattice CTRL/C handling */
  49. int chkabort(void) { return(0); }  /* really */
  50. #endif
  51.  
  52. struct Library *IntuitionBase;
  53.  
  54. /* our function prototypes */
  55. VOID handle_window_events(struct Window *win);
  56.  
  57.  
  58. /*
  59. ** Open a simple window on the default public screen,
  60. ** then leave it open until the user selects the close gadget.
  61. */
  62. VOID main(int argc, char **argv)
  63. {
  64. struct Window *test_window = NULL;
  65. struct Screen *test_screen = NULL;
  66.  
  67. IntuitionBase = OpenLibrary("intuition.library",37);
  68. if (IntuitionBase)
  69.     {
  70.     /* get a lock on the default public screen */
  71.     if (test_screen = LockPubScreen(NULL))
  72.             {
  73.             /* open the window on the public screen */
  74.             test_window = OpenWindowTags(NULL,
  75.                     WA_Left,  10,    WA_Top,    20,
  76.                     WA_Width, 300,   WA_Height, 100,
  77.                     WA_DragBar,         TRUE,
  78.                     WA_CloseGadget,     TRUE,
  79.                     WA_SmartRefresh,    TRUE,
  80.                     WA_NoCareRefresh,   TRUE,
  81.                     WA_IDCMP,           IDCMP_CLOSEWINDOW,
  82.                     WA_Title,           "Window Title",
  83.                     WA_PubScreen,       test_screen,
  84.                     TAG_END);
  85.  
  86.             /* Unlock the screen.  The window now acts as a lock on
  87.             ** the screen, and we do not need the screen after the
  88.             ** window has been closed.
  89.             */
  90.             UnlockPubScreen(NULL, test_screen);
  91.  
  92.             /* if we have a valid window open, run the rest of the
  93.             ** program, then clean up when done.
  94.             */
  95.             if (test_window)
  96.                 {
  97.                 handle_window_events(test_window);
  98.                 CloseWindow(test_window);
  99.                 }
  100.             }
  101.     CloseLibrary(IntuitionBase);
  102.     }
  103. }
  104.  
  105. /*
  106. ** Wait for the user to select the close gadget.
  107. */
  108. VOID handle_window_events(struct Window *win)
  109. {
  110. struct IntuiMessage *msg;
  111. BOOL done = FALSE;
  112.  
  113. while (! done)
  114.     {
  115.     /* We have no other ports of signals to wait on,
  116.     ** so we'll just use WaitPort() instead of Wait()
  117.     */
  118.     WaitPort(win->UserPort);
  119.  
  120.     while ( (! done) &&
  121.             (msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
  122.         {
  123.         /* use a switch statement if looking for multiple event types */
  124.         if (msg->Class == IDCMP_CLOSEWINDOW)
  125.             done = TRUE;
  126.  
  127.         ReplyMsg((struct Message *)msg);
  128.         }
  129.     }
  130. }
  131.